package web;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class BeanUser extends HttpServlet {
    @Override
    public void service(HttpServletRequest request, HttpServletResponse response){

        try {
            Class c = this.getClass();
            Object o = c.newInstance();
            String methodName = request.getParameter("methodName");

            if (methodName == null) {
                methodName = "index";
            }
            Method method = c.getMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
            method.invoke(o, request, response);
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            throw new RuntimeException("程序反射异常...") ;
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

    }
}
